home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
nodefnd
/
gridbrow.bas
< prev
next >
Wrap
BASIC Source File
|
1995-10-23
|
8KB
|
267 lines
'Programer : Antonio Macedo
'Compuserve : 75210.3332
'Date : 10/06/93
'Version : 1.0
'Total Hours: 7
'The folowing code is designed to be as generic as possible,
'so you can easyly implement it on your aplication.
'Feel free to use and distribute this code.
'Just do me three favors :
'- Send me an message telling what you think about this routines.
'- Send me an message telling the modifications that you have made on the routines.
'- DO NOT DELETE MY COMMENTS, ESPECIALY CREDITS AND THESE THREE FAVORS.
'This is the array used to hold bookmarks for the grid operations
'adjust the first dimension maching the number of grids you use
'adjust the second dimension maching the maximum # of rows on the grids
Global Mark(1 To 1, 0 To 15) As String
'<<< I M P O R T A N T >>>
'- Do not forget to open the files and fill the grid
' and the bookmark array with data.
Sub Grd_Copy (Grd As Grid, ByVal r, ByVal c, ByVal r2, ByVal c2 As Integer)
'Copy text from
' r , c
'To
' r2, c2
'In grid Grd
Static s As String
Grd.Row = r
Grd.Col = c
s = Grd.Text
Grd.Row = r2
Grd.Col = c2
Grd.Text = s
End Sub
Sub Grd_Write (Grd As Grid, ByVal r As Integer, ByVal c As Integer, ByVal s As String)
'Write string
' s
'To
' r , c
'In grid Grd
Grd.Row = r
Grd.Col = c
Grd.Text = s
End Sub
Sub Grid_Browse (KeyCode As Integer, Shift As Integer, Grd As Grid, Tbl As Table, bk As Integer)
'Parameters definition
'KeyCode - Comes directly from KeyDown event
'Shift - Comes directly from KeyDown event
'Grd - Grid control where the cursor is located
'Tbl - Table object that is the data source
'bk - Bookmark array index corresponding to the current Grid
' -----
Static CurRow, Range As Integer
'Check for UnderFlow
'If the table does not fill entirely the grid then exit
If Mark(bk, Grd.Rows - 1) = "" Then Exit Sub
'{PgDn} or {Ctrl}+{PgDn} or {Ctrl}+{Down}
If ((KeyCode = 34) Or (KeyCode = 40 And Shift = 2)) And Not Tbl.EOF Then
'Go to the bookmark corresponding to the last grid line
Tbl.Bookmark = Mark(bk, Grd.Rows - Grd.FixedRows)
'Store the cursor position
CurRow = Grd.Row
'If {PgDn} or {Ctrl}+{Down} then range = grid number of lines
'If {Ctrl}+{PgDn} then range = 3 times grid number of lines
If KeyCode = 34 And Shift = 2 Then
Range = (Grd.Rows - Grd.FixedRows) * 3
Else
Range = Grd.Rows - Grd.FixedRows
End If
'MoveNext until range or EOF
For r = Grd.FixedRows To Range
Tbl.MoveNext
If Tbl.EOF Then
Tbl.MovePrevious
Exit For
End If
Next
'Refresh grid and bookmark array data backwards
For r = Grd.Rows - 1 To Grd.FixedRows Step -1
For c = Grd.FixedCols To Grd.Cols - 1
Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
Next
Mark(bk, r) = Tbl.Bookmark
Tbl.MovePrevious
Next
'Restore cursor position
Grd.Row = CurRow
'Change KeyCode value to trig the SelChange event
KeyCode = 37
End If
'{PgUp} or {Ctrl}+{PgUp} or {Ctrl}+{Up}
If ((KeyCode = 33) Or (KeyCode = 38 And Shift = 2)) And Not Tbl.BOF Then
'Go to the bookmark corresponding to the first grid line
Tbl.Bookmark = Mark(bk, Grd.FixedRows)
'Store the cursor position
CurRow = Grd.Row
'If {PgUp} or {Ctrl}+{Up} then range = grid number of lines
'If {Ctrl}+{PgUp} then range = 3 times grid number of lines
If KeyCode = 33 And Shift = 2 Then
Range = (Grd.Rows - Grd.FixedRows) * 3
Else
Range = Grd.Rows - Grd.FixedRows
End If
'MovePrevious until range or BOF
For r = Grd.FixedRows To Range
Tbl.MovePrevious
If Tbl.BOF Then
Tbl.MoveNext
Exit For
End If
Next
'Refresh grid and bookmark array data
For r = Grd.FixedRows To Grd.Rows - 1
For c = Grd.FixedCols To Grd.Cols - 1
Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
Next
Mark(bk, r) = Tbl.Bookmark
Tbl.MoveNext
Next
'Restore cursor position
Grd.Row = CurRow
'Change KeyCode value to trig the SelChange event
KeyCode = 37
End If
'{Down} on the last grid line - Scroll Down
If Grd.Row = Grd.Rows - Grd.FixedRows And KeyCode = 40 And Not Tbl.EOF Then
'Go to the bookmark corresponding to the last grid line
Tbl.Bookmark = Mark(bk, Grd.Rows - Grd.FixedRows)
'Read the next record
Tbl.MoveNext
If Not Tbl.EOF Then
'Scroll grid and bookmark array data one row up
For r = Grd.FixedRows To (Grd.Rows - Grd.FixedRows) - 1
For c = Grd.FixedCols To Grd.Cols - 1
Grd_Copy Grd, r + 1, c, r, c
Next
Mark(bk, r) = Mark(bk, r + 1)
Next
'Write the current record on the last grid line
For c = Grd.FixedCols To Grd.Cols - 1
Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
Next
'Update bookmark array
Mark(bk, Grd.Rows - Grd.FixedRows) = Tbl.Bookmark
End If
End If
'{Up} on the first grid line - Scroll Up
If Grd.Row = Grd.FixedRows And KeyCode = 38 And Not Tbl.BOF Then
'Go to the bookmark corresponding to the first grid line
Tbl.Bookmark = Mark(bk, Grd.FixedRows)
'Read the previous record
Tbl.MovePrevious
If Not Tbl.BOF Then
'Scroll grid and bookmark array data one row down
For r = Grd.Rows - 1 To Grd.FixedRows + 1 Step -1
For c = Grd.FixedCols To Grd.Cols - 1
Grd_Copy Grd, r - 1, c, r, c
Next
Mark(bk, r) = Mark(bk, r - 1)
Next
'Write the current record on the first grid line
For c = Grd.FixedCols To Grd.Cols - 1
Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
Next
'Update bookmark array
Mark(bk, Grd.FixedRows) = Tbl.Bookmark
End If
End If
'{A} to {Z} - Seek first record begining with the pressed letter using the current index
If KeyCode >= 65 And KeyCode <= 90 Then
Tbl.Seek ">=", Chr$(KeyCode)
If Not Tbl.NoMatch Then
'Refresh grid and bookmark array data
For r = Grd.FixedRows To Grd.Rows - 1
For c = Grd.FixedCols To Grd.Cols - 1
Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
Next
Mark(bk, r) = Tbl.Bookmark
Tbl.MoveNext
Next
'Put the cursor on the first grid line
Grd.Row = Grd.FixedRows
'Change KeyCode value to trig the SelChange event
KeyCode = 37
End If
End If
'{Home} - Put the cursor on the first grid row
If KeyCode = 36 Then
Grd.Row = Grd.FixedRows
End If
'{End} - Put the cursor on the last grid row
If KeyCode = 35 Then
Grd.Row = Grd.Rows - Grd.FixedRows
End If
'{Ctrl}+{Home} - Go to the first record
If KeyCode = 36 And Shift = 2 Then
Tbl.MoveFirst
'Refresh grid and bookmark array data
For r = Grd.FixedRows To Grd.Rows - 1
For c = Grd.FixedCols To Grd.Cols - 1
Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
Next
Mark(bk, r) = Tbl.Bookmark
Tbl.MoveNext
Next
End If
'{Ctrl}+{End} - Go to the last record
If KeyCode = 35 And Shift = 2 Then
Tbl.MoveLast
'Refresh grid and bookmark array data backwards
For r = Grd.Rows - 1 To Grd.FixedRows Step -1
For c = Grd.FixedCols To Grd.Cols - 1
Grd_Write Grd, r, c, Tbl(c - Grd.FixedCols)
Next
Mark(bk, r) = Tbl.Bookmark
Tbl.MovePrevious
Next
End If
End Sub